package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NursingProjectImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;
    /**
     * 条件分页查询
     *
     * @param name     项目名称
     * @param pageNum  当前页面
     * @param pageSize 每页条数
     * @param status   状态
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> list(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProjectVo> page =nursingProjectMapper.list(name, status);
        PageResponse<NursingProjectVo> pageResponse=new PageResponse<>();
        pageResponse.setPage(pageNum);
        pageResponse.setPageSize(pageSize);
        pageResponse.setTotal(page.getTotal());
        pageResponse.setRecords(page.getResult());
        return pageResponse;
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto 护理项目VO
     */
    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
        nursingProjectMapper.add(nursingProject);
    }

    /**
     * 根据ID查询
     *
     * @param id ID
     * @return
     */
    @Override
    public NursingProjectVo findById(Long id) {
        NursingProjectVo nursingProjectVo = new NursingProjectVo();
        NursingProject nursingProject = nursingProjectMapper.findById(id);
        BeanUtils.copyProperties(nursingProject, nursingProjectVo);
        return nursingProjectVo;
    }

    /**
     * 编辑护理项目
     *
     * @param nursingProjectDto 护理项目VO
     */
    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto, nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 删除护理项目
     *
     * @param id ID
     */
    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    /**
     * 启用/禁用护理项目
     *
     * @param id     ID
     * @param status 状态
     */
    @Override
    public void enableOrDisable(Long id, Integer status) {
        if (0==status){
            nursingProjectMapper.updateStatus(id, 1);
        }else if (1==status){
            nursingProjectMapper.updateStatus(id, 0);
        }
    }
}
